package com.lagou.dao.impl;

import com.lagou.dao.AccountDao;
import com.lagou.utils.ConnectionUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;

/**
 * @program: spring_transfer
 * @description:
 * @author: Mr.Wang
 * @create: 2020-12-16 09:32
 **/
@Repository("accountDao")
public class AccountDaoImpl implements AccountDao {
	@Autowired
	private QueryRunner queryRunner;

	@Autowired
	private ConnectionUtils connectionUtils;

	public void out(String username, Double money) {
		String sql = "update account set money = money - ? where name = ?";
		try {
			queryRunner.update(connectionUtils.getConnection(),sql,money,username);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void in(String username, Double money) {
		String sql = "update account set money = money + ? where name = ?";
		try {
			queryRunner.update(connectionUtils.getConnection(),sql,money,username);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
